<?php

class LastFMAPI {
	
	protected $auth;
	protected $url;
	
	protected function __construct(array $auth){
		$this->auth = $auth;
		$this->url = "http://ws.audioscrobbler.com/2.0/";	
	}
	
	public static function getInstance($auth,$class){
		$className = "LastFMAPI_$class";	
		return new $className($auth);
	}
	
	protected function makeRequest($method, $methodParamArray = array() ){
		$paramArray = array("api_key" => $this->auth["apiKey"], "method" => $method);
		$paramArray =  array_merge($paramArray,$methodParamArray);
		$resultat = Outils_Connexion::curl_post($this->url,$paramArray);
		return $this->getXMLResult($resultat);
	}
	
	protected function getXMLResult($str){
		$xml =  simplexml_load_string($str);
		if ($xml[0]['status'] == "ok"){
			return $xml;
		} else {
			throw new Exception($xml->error);
		}
	}
	
	
	
}


?>